<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="en">
<?php $title = '编辑服务项目'; ?>
<head>
	<meta charset="UTF-8">
	<title><?php echo ($title); ?></title>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
	<link rel="stylesheet" href="/Application/Home/View//Public/static/css/weui.min.css"/>
    <link rel="stylesheet" href="/Application/Home/View//Public/static/css/jquery-weui.min.css"/>
    <link rel="stylesheet" href="/Application/Home/View//Public/static/css/custom.css"/>
    <style type="text/css">
		body{
			background:#f1f1f1;
			color:#a3a3a3;
			font-family:"Microsoft YaHei";
		}
		.bd{
			padding:20px;
		}
        li{list-style: none;}
		p{
			font-size: 13px;
		}
		.weui-cell_select-before .weui-cell__hd:before{
			border-width: 0px 2px 2px 0;
			margin-top: -6px;
		}
		.weui-cell_select-before .weui-cell__hd:after{border:none;}
        .sstmb {
            padding-bottom: 60px;
        }
        .foot-ul{
			text-align:center;
			margin-top: 1rem;
			padding:10px;
			background: #22a9fe;
			opacity: 0.9;
		}
		.foot-ul a{
			color: #fff;
		}
		.foot-ul a img{
			max-width: 24px;
		}
		.pinglun{
			padding: 0 2px;
			background: #ff5959;
			border-radius: 50px;
			color: #fff;
			position: absolute;
			top:-6px;
			left:73px;
			font-size: 13px;
		}
		
		
		.weui-cell__bd p{
		color:#6b6969;
		}
        
	</style>
</head>

<body ontouchstart>

  <style type="text/css">
    .weui-cell:before{
      right:15px;
    }
    
    .weui-cells{
      margin-top: 0;
    }
    body{
      background:#f1f1f1;
      color:#3b3b3b;
      font-family:"Microsoft YaHei";
    }
    .weui-cell__ft p{
      color:#189ce0;
      margin-right:.5rem
    }
    .weui-cell__ft img{
      width:3.5rem;
      margin-right:.3rem;
      display:block;
      border-radius: 80px;
    }
    .line{
      width: 3rem;
      height: 1px;
      background: #909090;
      margin:50% auto;
    }
     .line2{
      width: 1px;
      height: 3rem;
      background: #909090;
      margin:-81% auto;
    }


    
  </style>
    <div class="container js_container">

    </div>

<div class="page">
<header class="demos-header head-title">
	<a class="back" href="<?php echo U('ServiceItem/index');?>">
      <img style="width:10px;" src="/Application/Home/View//Public/static/images/back.png">
	</a>
	  <span>项目编辑</span>
	<a class="home" href="<?php echo U('Card/index');?>&userid=<?php echo (session('userid')); ?>">  
	  <img src="/Application/Home/View//Public/static/images/home.png">
	</a>
    </header>


<!--   访客统计-->
<div  class="weui-cells">
          <form method="POST" action='<?php echo U("ServiceItem/post_img");?>' enctype="multipart/form-data" id="icon_form">
          <a style="height: auto;" class="weui-cell weui-cell_access" href="javascript:;">
              <div class="weui-cell__bd">
                <p>图标</p>
              </div>
              <div class="weui-cell__ft">
              <input class="weui-uploader__input" type="file" id='service_item_icon' name='img' accept="image/*" multiple="" onchange='$("#icon_form").submit();'>
              <?php if($row["icon"] != ""): ?><img src="/uploads/<?php echo ($row["icon"]); ?>" id="icon" data-src="<?php echo ($row["icon"]); ?>" />
              <?php else: ?>
              <img src="/Application/Home/View//Public/static/images/ed03.png" id="icon" data-src="" /><?php endif; ?>
              </div>
           </a>
           </form>
           
          <div class="weui-cell weui-cell_access" >
            <div class="weui-cell__hd"><label class="weui-label">标题</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input red" id="title" placeholder="请输入标题" value="<?php echo ($row["title"]); ?>">
            </div>
          </div>
          
          <div class="weui-cell weui-cell_access" >
            <div class="weui-cell__hd"><label class="weui-label">排序</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input red" id="sort" type="number" placeholder="请输入排序" value="<?php echo ($row["sort"]); ?>">
            </div>
          </div>
         
          <div class="weui-cells__title" style="background:rgba(0,0,0,0.1);height:40px;line-height:40px;color:#9A9A9A;margin:0;">内容</div>
          <div class="weui-cells weui-cells_form">
              <div class="weui-cell">
                <div class="weui-cell__bd">
                  <textarea class="weui-textarea" id="content" placeholder="请输入文本" rows="3" name="content"><?php echo ($row["content"]); ?></textarea>
                </div>
              </div>
            </div>
            
          
          <div class="weui-cell weui-cell_access" >
            <div class="weui-cell__hd"><label class="weui-label">添加图片</label></div>
          </div>
          <div style="padding:10px;">
            <p></p>
            <div class="weui-uploader__bd">
              <ul class="weui-uploader__files" id="uploaderFiles">
                 <?php if(is_array($imgs)): $i = 0; $__LIST__ = $imgs;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i; if($vo != ''): ?><li class="weui-uploader__file" style="background-image:url(/uploads/<?php echo ($vo); ?>);position:relative" data-src="<?php echo ($vo); ?>">
                        <img src="/Application/Home/View//Public/static/images/close-fill.png" style="position:absolute;right:0;top:0;width:20px" onclick='$(this).parent().remove();'/>
                     </li><?php endif; endforeach; endif; else: echo "" ;endif; ?>
              </ul>
              <form method="POST" action='<?php echo U("ServiceItem/post_img");?>' enctype="multipart/form-data" id="imgs_form">
              <div class="weui-uploader__input-box">
                <input class="weui-uploader__input" type="file" accept="image/*" name='img'  onchange='$("#imgs_form").submit();'>
              </div>
              </form>
            </div>
          </div>
          <input type="hidden" id="id" value="<?php echo ($id); ?>" />
        <div style="margin:1rem  auto;width:15rem;border-radius:20px;" class='demos-content-padded'>
          <button style="background:#22a9fe;" class="weui-btn weui-btn_primary" onclick="save();">保存</button>
        </div>
  </div>
    <script src="/Application/Home/View//Public/static/js/jquery-2.1.4.js"></script>
    <script src="/Application/Home/View//Public/static/js/jquery-weui.min.js"></script>
    <script src="/Application/Home/View//Public/static/js/fastclick.js"></script>
    <script src="/Application/Home/View//Public/static/layer/layer.js"></script>
    <script src="/Application/Home/View//Public/static/js/jquery.form.js"></script>
    <script>
      $(function() {
        FastClick.attach(document.body);
      });
    </script>
</body>
</html>

<script>
    $(function(){
          $("#icon_form").ajaxForm(function(data){
              var data = JSON.parse(data);
              if(data.status == 1){
                  var img_url = data.msg;
                  $("#icon").attr('src', img_url);
                  $("#icon").attr('data-src', img_url.replace('./uploads', ''));
              }else{
                  $.alert(data.msg);
              }
          })
          
          $("#imgs_form").ajaxForm(function(data){
              var data = JSON.parse(data);
              if(data.status == 1){
                  var img_url = data.msg;
                  $("#uploaderFiles").append('<li class="weui-uploader__file" style="background-image:url('+img_url+')" data-src="'+img_url+'"></li>');
              }else{
                  $.alert(data.msg);
              }
          })
      })
      
      function save(){
          if($.trim($("#title").val()) == ''){
              $.toptip('请输入标题', 'error');
          }else{
              var icon = $("#icon").attr("data-src");
              var title = $("#title").val();
              var sort = $("#sort").val();
              var content = $("#content").val();
              var imgs = '';
              for(var i=0; i<$("#uploaderFiles li").length;i++){
                 imgs += $("#uploaderFiles li").eq(i).attr("data-src").replace('./uploads', '')+",";
              }
              imgs = imgs.substr(0, imgs.length);
              $.ajax({
                 url:'<?php echo U("ServiceItem/save");?>',
                 data:{"icon":icon,"title":title,"sort":sort,"content":content,"imgs":imgs, "id":$("#id").val()},
                 type:"POST",
                 success:function(data){
                     if(data == 1){
                         $.toast("操作成功!", function(){
                             location.href="<?php echo U('ServiceItem/index');?>";
                         });
                         
                     }else{
                         $.toast("操作失败，请稍后重试!", "forbidden");
                     }
                 }
              })
          }
      }
</script>